#include "LDragAssist.h"

namespace ln
{

    LDragAssist::LDragAssist()
        : is_start_point_y_down(true),
        m_is_mouse_down(false)
    {
        m_start_point.m_x = 0;
        m_start_point.m_y = 0;
    }

    void LDragAssist::SetIsStartPointYDown(bool isDown)
    {
        is_start_point_y_down = isDown;
    }


    void LDragAssist::SetStartPoint(int x, int y)
    {
        m_start_point.m_x = x;
        m_start_point.m_y = y;
    }

    void LDragAssist::SetStartPoint(const ln::PointInt &p)
    {
        SetStartPoint(p.m_x, p.m_y);
    }

    void LDragAssist::MouseDown(int x, int y)
    {
        m_down_point.m_x = x;
        m_down_point.m_y = y;

        m_is_mouse_down = true;
    }

    void LDragAssist::MouseDown(const ln::PointInt &p)
    {
        MouseDown(p.m_x, p.m_y);
    }

    void LDragAssist::MouseUp()
    {
        m_is_mouse_down = false;
    }

    ln::PointInt LDragAssist::MouseMove(int x, int y)
    {
        ln::PointInt new_point;
        new_point.m_x = m_start_point.m_x + (x - m_down_point.m_x);

        if(is_start_point_y_down)
            new_point.m_y = m_start_point.m_y + (y - m_down_point.m_y);
        else
            new_point.m_y = m_start_point.m_y - (y - m_down_point.m_y);

        m_start_point.m_x = new_point.m_x;
        m_start_point.m_y = new_point.m_y;
        m_down_point.m_x = x;
        m_down_point.m_y = y;

        return new_point;
    }

    ln::PointInt LDragAssist::MouseMove(const ln::PointInt &p)
    {
        return MouseMove(p.m_x, p.m_y);
    }

    bool LDragAssist::IsMouseDown() const
    {
        return m_is_mouse_down;
    }
}